package com.timeDeal.servlet;

import com.alibaba.druid.util.StringUtils;
import com.timeDeal.bean.ShijianchushouBean;
import com.timeDeal.bean.UserBean;
import com.timeDeal.service.ChushouService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;

/**
 * Created by wzq on 2016/9/11 0011.
 * 处理出售时间页面传过来的信息
 */

public class ChushouServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserBean loginuser =(UserBean) request.getSession().getAttribute("USER") ;
        String ability = request.getParameter("jineng");
        String startDate = request.getParameter("kaishishijian") ;
        String endDate = request.getParameter("jieshushijian") ;
        String area = request.getParameter("huodongquyu");
        String beizhu = request.getParameter("beizhu");
        String shifoujingbiao=request.getParameter("shifoujingbiao");
        String choulaoxiaxian=request.getParameter("choulaoxiaxian");
        String jingbiaoqixian=request.getParameter("jingbiaoqixian");
        String choulao=request.getParameter("choulao");
        String mingchneg=request.getParameter("mingchneg");


        ShijianchushouBean sjcsb = new ShijianchushouBean() ;
         sjcsb.setJiafangid(loginuser.getYonghuid());
        sjcsb.setJineng(ability);
        sjcsb.setShijianchushoumingcheng(mingchneg);
        sjcsb.setKaishiriqi(Date.valueOf(startDate));//格式化时间
        sjcsb.setJieshuriqi(Date.valueOf(endDate));
        sjcsb.setQuyu(area);
        sjcsb.setBeizhu(beizhu);
        sjcsb.setZhuangtai("待审核");
        if(StringUtils.equals(shifoujingbiao,"是")){
            sjcsb.setChoulaoxiaxian(Integer.valueOf(choulaoxiaxian));
            sjcsb.setJingbiaoriqi(Date.valueOf(jingbiaoqixian));
        }
        else{
            sjcsb.setChoulaoxiaxian(0);
            sjcsb.setJingbiaoriqi(null);
        }
        sjcsb.setChoulao(Integer.valueOf(choulao));
        sjcsb.setYunxujingbiao(shifoujingbiao);
        ChushouService chushouService = new ChushouService() ;
        chushouService.addItem(sjcsb);
        request.getRequestDispatcher("/user/zhujiemiangg.jsp").forward(request,response);
    }
}
